﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web.Http;
using Microsoft.Owin.Security.OAuth;
using Newtonsoft.Json.Serialization;
using System.Web.Http.Tracing;
using Architecture.CrossCutting.WebApi;

namespace PresentationService
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {

            //Replace default Microsoft.AspNet.WebApi.Tracing by custom implementation
            config.Services.Replace(typeof(System.Web.Http.Tracing.ITraceWriter), new EtwWebapiTraceWriter());

            //Activate Microsoft.AspNet.WebApi.Tracing
/*            SystemDiagnosticsTraceWriter traceWriter = config.EnableSystemDiagnosticsTracing();
            traceWriter.IsVerbose = true;
            traceWriter.MinimumLevel = TraceLevel.Debug;
            */

            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}
